import request from '@/utils/request'
import type { LifeEntity, PageResponse, LifeEntityCreateRequest, LifeEntityUpdateRequest } from './types'

// 生命体API服务
export const lifeEntityApi = {
  // 获取生命体列表
  getList(params: {
    page?: number
    size?: number
    type?: string
    status?: string
    search?: string
    sort?: string
    direction?: string
  }): Promise<PageResponse<LifeEntity>> {
    return request.get('/life-entities', { params })
  },

  // 获取生命体详情
  getById(id: string): Promise<LifeEntity> {
    return request.get(`/life-entities/${id}`)
  },

  // 创建生命体
  create(data: LifeEntityCreateRequest): Promise<LifeEntity> {
    return request.post('/life-entities', data)
  },

  // 更新生命体
  update(id: string, data: LifeEntityUpdateRequest): Promise<LifeEntity> {
    return request.put(`/life-entities/${id}`, data)
  },

  // 删除生命体
  delete(id: string): Promise<void> {
    return request.delete(`/life-entities/${id}`)
  },

  // 激活生命体
  activate(id: string): Promise<LifeEntity> {
    return request.post(`/life-entities/${id}/activate`)
  },

  // 休眠生命体
  dormant(id: string): Promise<LifeEntity> {
    return request.post(`/life-entities/${id}/dormant`)
  },

  // 进化生命体
  evolve(id: string): Promise<LifeEntity> {
    return request.post(`/life-entities/${id}/evolve`)
  },

  // 获取生命体统计信息
  getStatistics(): Promise<any> {
    return request.get('/life-entities/statistics')
  },

  // 获取活跃的生命体
  getActiveEntities(): Promise<LifeEntity[]> {
    return request.get('/life-entities/active')
  },

  // 获取需要关注的生命体
  getEntitiesNeedingAttention(): Promise<LifeEntity[]> {
    return request.get('/life-entities/attention-needed')
  },

  // 获取最近活跃的生命体
  getRecentlyActiveEntities(hours: number = 24): Promise<LifeEntity[]> {
    return request.get('/life-entities/recently-active', { params: { hours } })
  },

  // 批量更新状态
  batchUpdateStatus(ids: string[], status: string): Promise<void> {
    return request.put('/life-entities/batch/status', null, { 
      params: { ids: ids.join(','), status } 
    })
  },
}
